<?php
class LocationProvincesFForm extends BaseFormAdmin{
	public function configure(){
		$langs = SysLanguages::getAllLang();
		foreach($langs as $lang){
			$this->setWidget('name_'.$lang, new sfWidgetFormInputText(array(), array('class' => 'required hz-required')));
			$this->setValidator('name_'.$lang, new sfValidatorString(array('max_length' => 255, 'required' => false)));
			
			$this->setWidget('description_'.$lang, new sfWidgetFormTextarea());
			$this->setValidator('description_'.$lang, new sfValidatorString(array('required' => false)));
			
		
		}
		
		$query = Doctrine_Query::create()
			->from('LocationAreas al')
			->leftJoin('al.LocationAreasI18n lang')
			->select('al.id, lang.name as name')
			->where('al.is_enabled = 1 AND al.is_deleted = 0')
			->andWhere('(al.updated_at IS NULL OR al.updated_at >= al.created_at)')
			->andWhere('lang.lang = ?', SysLanguages::getCurrentLang())
			->orderBy('lang.name asc');
		
		$this->setWidget('location_area_id',new sfWidgetFormDoctrineChoice(array(
				'model' 		=> 'LocationAreas',
				'query'			=> $query,
				'multiple' 		=> false,
				'add_empty' 	=> __('select-option-all')), array('class' =>'required hz-required')
		));
		$this->setValidator('location_area_id', new sfValidatorDoctrineChoice(array(
				'model' => 'LocationAreas',
				'query' => $query,
				'required' => true), array('required'=> 'error-select')
		));
		parent::configure();
	}
}
